
<?php 

/* ------------------------------------------------------------
 * Page:Review Booking
 * Author: Gustavo Lozano & Fredrik Kronander
 * Description:Show all booking and user submitted information and allow user to confirm the booking.
 * 
 **------------------------------------------------------------*/
 
	//Include Libraries
	require_once 'source/UtsAirs.php';	
	require_once 'source/User.php';	

    $message = "";
	$message .= "<table width=\"60%\" align=\"center\" border=\"1\">";
	
	
		$uts = unserialize($_SESSION["uts"]);
		$flights = $uts->flights;
	
		if( count($flights) > 0)
		{
		
			$message .= "<tr>";
			$message .= 	"<td>From</td>";
			$message .= 	"<td>To</td>";
			$message .= 	"<td>Seats</td>";
			$message .= "</tr>	";		
	
	
			foreach ($flights as $flight)
			{
				$message .=  "<tr>";
				$message .=  "<td>". $flight->fromCity."</td>";
				$message .=  "<td>". $flight->toCity. "</td>";
				
				$seats = $flight->seats;
				$i = 1;
				$message .=  "<td>";
				foreach ($seats as $s)
				{
					while (list($k,$v)= each($s))
					{
						if($v == 'YES')
						{
							if($k != CHECKED)
								$message .=  " ".$k;
							else
								$message .=  "<br>Seat ". $i. ":";
						}
					}
					$i++;
				}
				$message .=  "</td>";
				$message .=  "</tr>";
			}
	
		}
		else
		{
			$message +=  "<tr>";
			$message +=  "<td>There are no booked flights</td>";
			$message +=  "</tr>";
			
		}
	$message .= "</table>";

	
	if(isset($_REQUEST['competeBooking']) && $_REQUEST['competeBooking'] == "complete")
	{
		$user = unserialize($_SESSION['userinformation']);
		$uts = unserialize($_SESSION["uts"]);
		
	 	$subject = "Uts Airs Booking-".$user->givenName." ".$user->familyName;
	 	
	 	$reserve = rand(5, 15);
		$emailMess = "Thank you for your booking, your reserve number is ".$reserve. " \n \n \n";
		
		$emailMess .= "<html><body><br/><br/>";
		$emailMess .= $message; 	
		$emailMess .= "</body></html>";	
	
		$uts->sendEmailToUser($user->email,$subject,$emailMess);
		
		echo "Thank You! .... your booking has been completed and a confirmation email has been sent to your email address";
		session_destroy();
	}
	else 
	{
		
	
?>

	<strong>Do you confirm following booking?</strong> <br><br><br>
	

<strong>Stage 3 of 4 - Review Details</strong><br><br>
	Do you confirm following booking? <br>
	
	Personal information
	<?php
	
		$user = unserialize($_SESSION['userinformation']);
		
		$userarray =array("givenName", "familyName", "address1", "address2", "suburb", "state", "postcode", "country", "email", "mobilePhone", "businessPhone", "workPhone");
		$userarraynames =array("Given name", "Family name", "Address 1", "Address 2", "Suburb", "State", "Postcode", "Country", "E-mail", "Mobile phone", 	"Business phone", "Work phone");
		
		echo "<table width=30%' border='0' cellspacing='2' cellpadding='2'>";
		for ($counter = 0; $counter < count($userarray); $counter++)
		{
			if($user->$userarray[$counter] != NULL && $user->$userarray[$counter] != "")
				echo "<tr height='23px'><td><strong>".$userarraynames[$counter].":</strong></td><td>".$user->$userarray[$counter]."</td></tr>";
		}
		echo "</table>";
	?>
		
	<?php 
	
		$paymentarray =array("txtNameOnCard", "txtCardNumber", "txtMonth", "txtYear", "txtCVVNumber"); 
			
		foreach ($paymentarray as $value)
		{
			$user->$value = $_REQUEST[$value];
		}
		
		$_SESSION['userinformation']=serialize($user);
	?>
	
	<br/><br/>
	<strong>Flights Booked</strong>

	<?php echo $message;?>

	<form action="index.php?content=ReviewBooking" method="post" style="padding-top:10px">
		<input type="hidden" name="competeBooking" value="complete"/> 
		<input type="submit" value="Stage 4 - Confirm Payment"/>
	</form>
<?php 
	}
?>